|
|
 |
|
|
|
|
' Compute the ith component. Result(i) = 0
For j = 1 To 3
' Multiply vector components with the corresponding
' matrix entries in the ith column. Result(i) = Result(i) + V(j) * M(i, j)
Next j
Next i |
|
|
|
|
|
|
|
|
Matrix/Matrix Multiplication |
|
|
|
|
|
|
|
|
When you multiply two matrices, the result is a new matrix. To multiply two matrices, you can think of each row in the first matrix as a vector. You can then use vector/matrix multiplication to find the corresponding row in the result. |
|
|
|
|
|
|
|
|
The following Visual Basic code multiplies two matrices. Here L and R are two-dimensional arrays that represent the left and right matrices respectively. Result is a two-dimensional array that will hold the result. In other words, Result = L * R. |
|
|
|
 |
|
|
|
|
For i = 1 To 3
' Compute result row i. For j = 1 To 3 ' Compute the result in row i, column j. Result(i, j) = 0
For k = 1 to 3
Result(i, j) = Result(i, j) + L(i, k) * R(k, j)
Next k
Next j
Next i |
|
|
|
|
|
|
|
|
Now that you know how to multiply vectors and matrices, you can use them to represent transformations. You can represent translation by distance Tx in the X direction and Ty in the Y direction with the matrix: |
|
|
|
|
|
|
|
|
To apply the transformation to the point [x, y, 1], you multiply the vector by the matrix. |
|
|
|
|
|
|
|
|
The new vector [x + Tx, y + Ty, 1] correctly represents the point (x, y) after it has been translated to the point (x + Tx, y + Ty). |
|
|
|
|
|